home *** CD-ROM | disk | FTP | other *** search
/ MACD 5 / MACD 5.bin / polski_aminet / blabla / unpackutility_1.1 / unpackutility.e < prev    next >
Text File  |  1997-01-25  |  18KB  |  725 lines

  1. /*MAC2E triton.e*/
  2.  
  3. /*
  4. ** Written by Karol Bryd of BlaBla
  5. **
  6. ** 1.0 - 28.08.96 - first public version, this version used only unpack.library
  7. ** 1.1 - 23.01.97 - added posibility of using xfdmaster.library
  8. **
  9. */
  10.  
  11. OPT OSVERSION=37
  12. OPT PREPROCESS
  13.  
  14. MODULE 'triton','utility/tagitem','unpack','libraries/unpack', 'exec/memory'
  15. MODULE 'ReqTools','libraries/reqtools','intuition/intuition', 'xfdmaster', 'libraries/xfdmaster'
  16. MODULE 'exec/lists', 'exec/nodes','dos/dos','exec/io','gadtools','libraries/gadtools'
  17. MODULE 'intuition/gadgetclass','devices/trackdisk','exec/io','exec/ports'
  18.  
  19. ENUM ERR_OK,ERR_LIB,ERR_PRJ,ERR_APP,ERR_LIBT,ERR_LIBU,ERR_INFOC,ERR_KICK,
  20.      ERR_LIBR,ERR_LOCK,ERR_WIN,ERR_VISUAL,ERR_LIBG,ERR_RTALLOC
  21.  
  22. ENUM NONE,DETER,UNPACK,LOAD,SAVE
  23.  
  24. OBJECT tr_Message
  25.     trm_Project:LONG
  26.     trm_ID
  27.     trm_Class
  28.     trm_Data
  29.     trm_Code
  30.     trm_Qualifier
  31.     trm_Seconds
  32.     trm_Micros
  33.     trm_App:LONG
  34. ENDOBJECT
  35.  
  36. DEF name[250]:STRING,
  37.     file[250]:STRING,
  38.     path[250]:STRING,
  39.     path2[250]:STRING,
  40.     loaddir[250]:STRING,
  41.     length,address,
  42.     application=NIL,project,
  43.     list=NIL:PTR TO mlh,sver,
  44.     cinfo:PTR TO unpackinfo,
  45.     err=NIL,openhd=NIL,
  46.     string[200]:STRING,
  47.     cnt=NIL,dinfo=NIL,tracknr=NIL,
  48.     abort=FALSE,
  49.     win=NIL:PTR TO window,
  50.     glist=NIL,visual,scr,
  51.     gad:PTR TO gadget,len,
  52.     mainwin=NIL,reql:PTR TO rtfilerequester,
  53.     flist:PTR TO rtfilelist,pos=NIL,unit=NIL,
  54.     reqs:PTR TO rtfilerequester,
  55.     xfdbuffer:PTR TO xfdbufferinfo,
  56.     password:PTR TO CHAR, unpackl, xfdl, slaves, over, saved=TRUE
  57.  
  58.  
  59. PROC main() HANDLE
  60.  
  61. sver:='$VER: Unpack Utility 1.1 (23.01.97)\0'
  62.  
  63. IF (KickVersion(37))=NIL THEN Raise(ERR_KICK)
  64. IF (tritonbase:=OpenLibrary('triton.library',1))=NIL THEN Raise(ERR_LIBT)
  65.  
  66. xfdl:=unpackl:=TRUE
  67. IF (unpackbase:=OpenLibrary('unpack.library',34))=NIL THEN unpackl:=0
  68. IF (xfdmasterbase:=OpenLibrary('xfdmaster.library', 37))=NIL THEN xfdl:=0
  69.  
  70. IF xfdl=unpackl=NIL THEN Raise(ERR_LIB)
  71.  
  72. IF (reqtoolsbase:=OpenLibrary('reqtools.library',37))=NIL THEN Raise(ERR_LIBR)
  73. IF (gadtoolsbase:=OpenLibrary('gadtools.library',37))=NIL THEN Raise(ERR_LIBG)
  74.  
  75. IF (application:=Tr_CreateApp([TRCA_Name,'Unpack Utility',
  76.             TRCA_Info,'Program to decrunching files, uses unpack.library & xfdmaster.library',
  77.             TRCA_Version,'1.1',TRCA_Date,'23.01.97',0]))=NIL THEN Raise(ERR_APP)
  78.  
  79. IF (cinfo:=UpAllocCInfo())=NIL THEN Raise(ERR_INFOC)
  80.  
  81. IF (reql:=RtAllocRequestA(0,0))=NIL THEN Raise(ERR_RTALLOC)
  82. IF (reqs:=RtAllocRequestA(0,0))=NIL THEN Raise(ERR_RTALLOC)
  83.  
  84. NEW list;initlist(list)
  85.  
  86. LEA store(PC),A0
  87. MOVE.L A4,(A0)
  88.  
  89. StrCopy(path,'ram:',ALL)
  90.  
  91. doMain(application)
  92. Raise(ERR_OK)
  93. EXCEPT
  94. SELECT exception
  95.     CASE ERR_LIBT
  96.         WriteF('No triton.library !\n')
  97.     CASE ERR_KICK
  98.         WriteF('Needed Kickstart v.2.04+\n')
  99.     CASE ERR_APP
  100.         WriteF('Could not create triton application\n')
  101.     CASE ERR_PRJ
  102.         WriteF('Could not create triton project\n')
  103.     CASE ERR_LIB
  104.         WriteF('No xfdmaster.library or unpack.library !\n')
  105.     CASE ERR_INFOC
  106.         WriteF('Could not create unpackinfo structure\n')
  107.     CASE ERR_LIBR
  108.         WriteF('No reqtools.library\n')
  109.     CASE ERR_RTALLOC
  110.         WriteF('Could not create rtallocrequest structure\n')
  111. ENDSELECT
  112. closeall()
  113. CleanUp(0)
  114. ENDPROC
  115.  
  116. PROC closeall()
  117.  
  118.     IF reql THEN RtFreeRequest(reql)
  119.     IF reqs THEN RtFreeRequest(reqs)
  120.     IF mainwin THEN Tr_ReleaseWindow(mainwin)
  121.     IF application THEN Tr_DeleteApp(application)
  122.     IF cinfo THEN UpFreeCInfo(cinfo)
  123.     IF reqtoolsbase THEN CloseLibrary(reqtoolsbase)
  124.     IF gadtoolsbase THEN CloseLibrary(gadtoolsbase)
  125.     IF unpackbase THEN CloseLibrary(unpackbase)
  126.     IF xfdmasterbase THEN CloseLibrary(xfdmasterbase)
  127.     IF tritonbase THEN CloseLibrary(tritonbase)
  128.  
  129. ENDPROC
  130.  
  131. PROC doMain(app)
  132.  
  133. DEF trmsg:PTR TO tr_Message, close_me=FALSE, class, id
  134.  
  135. slaves:=TRMF_CHECKIT
  136. over:=TRMF_CHECKIT
  137.  
  138. project:=Tr_OpenProject(app,[WindowTitle('Unpack Utility 1.1'),WindowPosition(TRWP_CENTERDISPLAY),WindowUnderscore('_'), WindowID(1),
  139.     BeginMenu('Information'), MenuItem('A_About', 11), ItemBarlabel, MenuItem('Q_Quit', 12),
  140.     BeginMenu('Preferences'), MenuItem('U_Use external slaves', 13), TRMN_Flags, slaves, MenuItem('O_Overwrite?', 14), TRMN_Flags, over,
  141.  
  142.  
  143.     VertGroupA,
  144.         Space,
  145.         HorizGroupA,
  146.             Space, Button('_Unpack',1), Space,
  147.         EndGroup,
  148.         VertGroupA,
  149.  
  150. ->            Space,Button('Preferences',2), /* maybe somewhere in future... */
  151.  
  152.             SpaceS,
  153.  
  154.             HorizGroupA,
  155.                 Space, Button('_About',3), Space,
  156.             EndGroup,
  157.  
  158.             SpaceS,
  159.             HorizGroupA,
  160.                 Space,ListRO(list,4,0),Space,
  161.             EndGroup,
  162.  
  163.             SpaceS, NamedSeparator('Actual File'), SpaceS,
  164.  
  165.             HorizGroupA,
  166.                 Space, StringGadget(0,5),Space,
  167.             EndGroup,
  168.  
  169.             SpaceS, NamedSeparator('Path for LHA'), SpaceS,
  170.  
  171.             HorizGroupA,
  172.                 Space, StringGadget(path,6), GetDrawerButton(7), Space,
  173.             EndGroup,
  174.  
  175.            EndGroup, Space, EndGroup, Space,
  176. EndProject])
  177.  
  178.     Tr_SetAttribute(project,6,0,path)
  179.     mainwin:=Tr_ObtainWindow(project)
  180.  
  181.     WHILE (close_me=FALSE)
  182.     Tr_Wait(app,NIL)
  183.         IF (trmsg:=Tr_GetMsg(app))
  184.             IF (trmsg.trm_Project=project)
  185.             class:=trmsg.trm_Class
  186.             id:=trmsg.trm_ID
  187.                 SELECT class
  188.                     CASE TRMS_CLOSEWINDOW
  189.                         close_me:=TRUE
  190.  
  191.                     CASE TRMS_NEWVALUE
  192.                         IF id=13 THEN IF slaves=TRMF_CHECKED THEN slaves:=TRMF_CHECKIT ELSE slaves:=TRMF_CHECKED
  193.                         IF id=14 THEN IF over=TRMF_CHECKED THEN over:=TRMF_CHECKIT ELSE over:=TRMF_CHECKED
  194.  
  195.                         IF id=6
  196.                             StrCopy(path2,Tr_GetAttribute(project,6,0),ALL)
  197.  
  198.                             pos:=(StrLen(path2)-1)+path2
  199.  
  200.                             IF (Char(pos)<>Char(':'))
  201.                                 IF(Char(pos)<>Char('/'))
  202.                                     StrCopy(path, path2, ALL)
  203.                                     StrAdd(path, '/', 1)
  204.                                 ELSE
  205.                                     StrAdd(path, path2, ALL)
  206.                                 ENDIF
  207.                             ELSE
  208.                                     StrAdd(path, path2, ALL)
  209.                             ENDIF
  210.                         ENDIF
  211.  
  212.                     CASE TRMS_ACTION
  213.                         SELECT id
  214.  
  215.                         CASE 1
  216.                         IF StrLen(path)>1
  217.                             IF (request(LOAD))
  218.                             REPEAT
  219.                                 IF flist THEN makeallnames(flist.name)
  220.                                 flist:=flist.next
  221.                                 tracknr:=0
  222.                                 Tr_SetAttribute(project,5,0,file)
  223.                                 StringF(string,'Loading and unpacking file:\s',file)
  224.                                 dodaj(list,string)
  225.                                 StringF(string,'File length:\d bytes',FileLength(name))
  226.                                 dodaj(list,string)
  227.  
  228.  
  229.                                 IF xfdl THEN err:=decrunchxfd(name)
  230.  
  231.                                 IF err<>0 AND unpackl
  232.  
  233.                                     err:=unpack(name)
  234.  
  235.                                         IF err=NONE
  236.                                             StringF(string,'Unpacked length:\d bytes',length)
  237.                                             dodaj(list,string)
  238.                                             IF (cinfo.crunchtype<>1) AND (cinfo.crunchtype<>5)
  239.                                                 IF (request(SAVE))
  240.                                                     IF FileLength(name)<>-1
  241.                                                         IF over=TRMF_CHECKIT THEN cnt:=reqtoolsreq('Overwrite ?', 'YES|NO!')
  242.                                                         IF cnt=1
  243.  
  244.                                                             IF (openhd:=Open(name,MODE_NEWFILE))
  245.                                                                 IF Write(openhd,address,length)<>0 THEN saved:=TRUE ELSE saved:=FALSE
  246.                                                                 Close(openhd)
  247.                                                                 UpFreeFile(cinfo)
  248.                                                             ENDIF
  249.  
  250.                                                         ELSE
  251.                                                             saved:=FALSE
  252.                                                         ENDIF
  253.                                                     ELSE
  254.                                                             IF (openhd:=Open(name,MODE_NEWFILE))
  255.                                                                 IF Write(openhd,address,length)<>0 THEN saved:=TRUE ELSE saved:=FALSE
  256.                                                                 Close(openhd)
  257.                                                                 UpFreeFile(cinfo)
  258.                                                             ENDIF
  259.                                                     ENDIF
  260.                                                 ELSE
  261.                                                     saved:=FALSE
  262.                                                ENDIF
  263.                                             ENDIF
  264.                                             IF saved=TRUE THEN dodaj(list,'File saved') ELSE dodaj(list, 'File not saved')
  265.                                         ELSE
  266.                                             whyfail(err)
  267.                                         ENDIF
  268.                                 ENDIF
  269.                                     dodaj(list,'------------------------')
  270.                             UNTIL flist=NIL
  271.                             RtFreeFileList(flist)
  272.                             ENDIF
  273.                         ELSE
  274.                             reqtoolsreq('You MUST enter path(e.g. ram: or something else)','OK')
  275.                         ENDIF
  276.                             CASE 7
  277.                                 Tr_SetAttribute(project,6,0,setpath())
  278.                             CASE 3
  279.                                 about()
  280.                             CASE 11
  281.                                 about()
  282.                             CASE 12
  283.                                 close_me:=TRUE
  284.                         ENDSELECT
  285.                 ENDSELECT
  286.             Tr_ReplyMsg(trmsg)
  287.             ENDIF
  288.         ENDIF
  289.     ENDWHILE
  290. Tr_CloseProject(project)
  291. ENDPROC
  292.  
  293. PROC about()
  294. ENDPROC reqtoolsreq('Unpack Utility v.1.1\n' +
  295.                 'This program uses unpack.library\n' +
  296.                 'and xfdmaster.library\n\n' +
  297.                 'This is another production of...\n' +
  298.                 'BlaBla\n\n' +
  299.                 'This program is CardWare.\n' +
  300.                 'If you like it, send me a postcard\n' +
  301.                 'of your country or city.\n' +
  302.                 'For bug reports, new ideas write to:\n\n' +
  303.                 'Karol Bryd\nPiaski Brzustowskie 194a\n' +
  304.                 '27-520 Cmielow\n' +
  305.                 'woj. tarnobrzeg\n' +
  306.                 'POLAND\n\n' +
  307.                 'email: thufor@zeus.polsl.gliwice.pl\n' +
  308.                 'or kordi@lodz2.p.lodz.pl' ,'OK')
  309.  
  310. PROC decrunchxfd(sourcename)
  311.  
  312. DEF error, fh, maxpasswordlen
  313.  
  314.     IF (xfdbuffer:=XfdAllocObject(XFDOBJ_BUFFERINFO))=NIL THEN RETURN ERR_MEMORY
  315.     len:=FileLength(sourcename)
  316.     IF slaves=TRMF_CHECKED THEN xfdbuffer.flags:=XFDFF_RECOGEXTERN
  317.  
  318.     xfdbuffer.sourcebuflen:=len
  319.     xfdbuffer.sourcebuffer:=New(len)
  320.     IF xfdbuffer.sourcebuffer=NIL
  321.         XfdFreeObject(xfdbuffer)
  322.         RETURN ERR_MEMORY
  323.     ENDIF
  324.  
  325.     IF (fh:=Open(sourcename, MODE_OLDFILE))=NIL THEN error:=ERR_OPEN
  326.     IF (Read(fh, xfdbuffer.sourcebuffer, len))=NIL THEN error:=ERR_READWRITE
  327.     IF fh THEN Close(fh)
  328.  
  329.     IF XfdRecogBuffer(xfdbuffer)
  330.  
  331.         dodaj(list, 'Unpacking file using xfdmaster.library')
  332.         StringF(string, 'File packed with:\s', xfdbuffer.packername)
  333.         dodaj(list, string)
  334.  
  335.         IF xfdbuffer.packerflags AND XFDPFF_PASSWORD
  336.  
  337.             IF xfdbuffer.error=-1 THEN maxpasswordlen:=63 ELSE maxpasswordlen:=xfdbuffer.error
  338.  
  339.             password:=String(maxpasswordlen)
  340.  
  341.             RtGetStringA(password, maxpasswordlen, 'Enter password:', NULL, NIL)
  342.  
  343.             xfdbuffer.special:=password
  344.  
  345.         ELSEIF xfdbuffer.packerflags AND XFDPFF_KEY16
  346.             RtGetLongA(xfdbuffer.special, 'Enter password', NIL, [RTGL_MIN, 0, RTGL_MAX, $ffff, TAG_DONE])
  347.  
  348.         ELSEIF xfdbuffer.packerflags AND XFDPFF_KEY32
  349.             RtGetLongA(xfdbuffer.special, 'Enter password', NIL, [RTGL_MIN, 0, RTGL_MAX, $ffffffff, TAG_DONE])
  350.  
  351.         ELSE
  352.             xfdbuffer.special:=NIL
  353.         ENDIF
  354.  
  355.         xfdbuffer.targetbufmemtype:=MEMF_ANY
  356.  
  357.         IF XfdDecrunchBuffer(xfdbuffer)
  358.  
  359.             IF request(SAVE)
  360.                 IF FileLength(name)<>-1
  361.                     maxpasswordlen:=1
  362.                     IF over=TRMF_CHECKIT THEN maxpasswordlen:=reqtoolsreq('Overwrite ?', 'YES|NO!')
  363.                     IF maxpasswordlen=1
  364.  
  365.                         IF (fh:=Open(name, MODE_NEWFILE))=NIL
  366.                             FreeMem(xfdbuffer.targetbuffer, xfdbuffer.targetbuflen)
  367.                             RETURN ERR_OPEN
  368.                         ENDIF
  369.  
  370.                         IF Write(fh, xfdbuffer.targetbuffer, xfdbuffer.targetbufsavelen)<>0 THEN saved:=TRUE ELSE saved:=FALSE
  371.                         IF fh THEN Close(fh)
  372.                     ELSE
  373.                         saved:=FALSE
  374.                     ENDIF
  375.                 ELSE
  376.                         IF (fh:=Open(name, MODE_NEWFILE))=NIL
  377.                             FreeMem(xfdbuffer.targetbuffer, xfdbuffer.targetbuflen)
  378.                             RETURN ERR_OPEN
  379.                         ENDIF
  380.  
  381.                         IF Write(fh, xfdbuffer.targetbuffer, xfdbuffer.targetbufsavelen)<>0 THEN saved:=TRUE ELSE saved:=FALSE
  382.                         IF fh THEN Close(fh)
  383.                 ENDIF
  384.  
  385.                 FreeMem(xfdbuffer.targetbuffer, xfdbuffer.targetbuflen)
  386.                 StringF(string, 'Length of unpacked file:\d', xfdbuffer.targetbufsavelen)
  387.                 IF saved=TRUE
  388.                     dodaj(list, string)
  389.                     dodaj(list, 'File saved')
  390.                 ELSE
  391.                     dodaj(list, 'File not saved')
  392.                 ENDIF
  393.                 error:=0
  394.             ELSE
  395.                 dodaj(list,'File not saved')
  396.             ENDIF
  397.         ELSE
  398.             error:=xfdbuffer.error
  399.         ENDIF
  400.  
  401.     ELSE
  402.         error:=xfdbuffer.error
  403.     ENDIF
  404.  
  405.     Dispose(xfdbuffer.sourcebuffer)
  406.     IF xfdbuffer THEN XfdFreeObject(xfdbuffer)
  407.  
  408. ENDPROC error
  409.  
  410. PROC moveup()
  411.  
  412. cnt:=cnt+1
  413. Tr_SetAttribute(project,4,TAG_USER+1506,cnt)
  414.  
  415. ENDPROC
  416.  
  417. PROC makeallnames(nazwa)
  418.  
  419. StrCopy(name,loaddir,ALL)
  420. StrCopy(file, nazwa, ALL)
  421. AddPart(name, nazwa, 150)
  422. ENDPROC
  423.  
  424. /* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% */
  425. /*             Procedury do obslugi list linkowalnych(laczonych)           */
  426. /*                                                                                                  */
  427. /*  Przy pisaniu tych procedur opieralem sie czesciowo na kodzie zrodlowym */
  428. /*  autorstwa Frank Verheyen                                               */
  429. /* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% */
  430.  
  431. PROC initlist(lista:PTR TO mlh)
  432.  
  433.     lista.head:=lista+4
  434.     lista.tail:=0
  435.     lista.tailpred:=lista
  436.  
  437. ENDPROC
  438. PROC dodaj(lista:PTR TO mlh,string)
  439.  
  440. DEF len=0,node:PTR TO ln,nnode:PTR TO ln
  441.  
  442. len:=StrLen(string)
  443. nnode:=New(SIZEOF ln)
  444. nnode.name:=String(len)
  445. nnode.succ:=0
  446. StrCopy(nnode.name,string,ALL)
  447. node:=lista.head
  448.     IF lista.tailpred=lista
  449.         AddHead(lista,nnode)
  450.     ELSE
  451.         AddTail(lista,nnode)
  452.     ENDIF
  453.     Tr_SetAttribute(project,4,0,list)
  454.     moveup()
  455.  
  456. ENDPROC
  457. PROC unpack(filename)
  458.  
  459. DEF id, class2, select, start, test=0
  460. DEF msg:PTR TO intuimessage, unittxt[25]:STRING
  461.  
  462.     cinfo.jump:=NIL
  463.     cinfo.trackjump:={scantrack}
  464.     cinfo.path:=path
  465.     cinfo.filename:=filename
  466.     cinfo.loadnamepoi:=NIL
  467.     cinfo.lhapattern:=NIL
  468.  
  469.     IF UpDetermineFile(cinfo,filename)=NIL
  470.         RETURN cinfo.errornum
  471.     ENDIF
  472.  
  473.     IF cinfo.crunchtype<>1 THEN cinfo.flag:=5 ELSE cinfo.flag:=0
  474.  
  475.     StringF(string,'File crunched with:\s',cinfo.crunchername)
  476.     dodaj(list,string)
  477.     IF cinfo.crunchtype=5
  478.         IF (scr:=LockPubScreen(0))=NIL THEN Raise(ERR_LOCK)
  479.         IF (visual:=GetVisualInfoA(scr,0))=NIL THEN Raise(ERR_VISUAL)
  480.         gad:=CreateContext({glist})
  481.         gad:=CreateGadgetA(BUTTON_KIND,gad,[5,12,75,15,'ABORT',NIL,1,0,visual,0]:newgadget,[GA_DISABLED,FALSE,GA_RELVERIFY,TRUE,0])
  482.         gad:=CreateGadgetA(BUTTON_KIND,gad,[82,12,72,15,'START',NIL,2,0,visual,0]:newgadget,[GA_DISABLED,FALSE,GA_RELVERIFY,TRUE,0])
  483.         gad:=CreateGadgetA(CYCLE_KIND,gad,[5,30,150,15,NIL,NIL,3,0,visual,0]:newgadget,[GA_DISABLED,FALSE,GA_RELVERIFY,TRUE,GTCY_LABELS,['DF0:','DF1:','DF2:',NIL],NIL])
  484.  
  485.         IF (win:=OpenWindowTagList(0,[WA_IDCMP,IDCMP_CLOSEWINDOW+IDCMP_REFRESHWINDOW+IDCMP_GADGETUP+IDCMP_GADGETDOWN,
  486.                          WA_LEFT,220,
  487.                          WA_TOP,100,
  488.                          WA_WIDTH,160,
  489.                          WA_HEIGHT,60,
  490.                          WA_TITLE,'DMS Unpacking',
  491.                          WA_GADGETS,glist,
  492.                          WA_FLAGS,WFLG_DRAGBAR+WFLG_CLOSEGADGET+WFLG_SMART_REFRESH+WFLG_DEPTHGADGET+WFLG_ACTIVATE,
  493.                          0,0]))=NIL THEN Raise(ERR_WIN)
  494.         Gt_RefreshWindow(win,0)
  495.         StrCopy(path,'df0:',ALL)
  496.         start:=FALSE; abort:=FALSE; test:=NIL
  497.         stdrast:=win.rport
  498.         SetTopaz(8)
  499.  
  500.     REPEAT
  501.  
  502.         WaitPort(win.userport)
  503.         IF (msg:=Gt_GetIMsg(win.userport))
  504.             class2:=msg.class
  505.             gad:=msg.iaddress
  506.             id:=gad.gadgetid
  507.                 IF class2=IDCMP_GADGETDOWN OR IDCMP_GADGETUP
  508.                     IF id=1 THEN abort:=TRUE
  509.                     IF id=2
  510.                         test:=checkdisk()
  511.                         SELECT test
  512.                             CASE 10
  513.                                 reqtoolsreq('Unprotect disk!','OK')
  514.                             CASE 100
  515.                                 reqtoolsreq('Insert disk!','OK')
  516.                             CASE 1000
  517.                                 StringF(unittxt,'DF\d is unavailable!',unit)
  518.                                 reqtoolsreq(unittxt,'OK')
  519.                         ENDSELECT
  520.                         IF test=0 THEN start:=TRUE ELSE start:=FALSE
  521.                     ENDIF
  522.                     IF id=3
  523.                     select:=msg.code
  524.                             SELECT select
  525.                                 CASE 0
  526.                                     StrCopy(path,'df0:',ALL)
  527.                                     unit:=0
  528.                                 CASE 1
  529.                                     StrCopy(path,'df1:',ALL)
  530.                                     unit:=1
  531.                                 CASE 2
  532.                                     StrCopy(path,'df2:',ALL)
  533.                                     unit:=2
  534.                             ENDSELECT
  535.                     ENDIF
  536.                 ENDIF
  537.             Gt_ReplyIMsg(msg)
  538.         ENDIF
  539.  
  540.     UNTIL (start=TRUE) OR (abort=TRUE)
  541.  
  542.     IF abort=TRUE
  543.  
  544.         closeall2()
  545.  
  546.         RETURN 999
  547.     ENDIF
  548.  
  549.     dinfo:=UpUseDrive(cinfo,path)
  550.     ENDIF
  551.  
  552.     dodaj(list, 'Unpacking file using unpack.library')
  553.  
  554.     IF (err:=UpUnpack(cinfo))=NIL
  555.         err:=cinfo.errornum
  556.  
  557.         closeall2()
  558.  
  559.         RETURN err
  560.     ENDIF
  561.  
  562.     closeall2()
  563.  
  564.     length:=cinfo.decrunchlen
  565.     address:=cinfo.decrunchadr
  566.  
  567. ENDPROC
  568.  
  569. PROC closeall2()
  570.  
  571.         IF dinfo     THEN UpUnuseDrive(dinfo)
  572.         IF win         THEN CloseWindow(win)
  573.         IF glist     THEN FreeGadgets(glist)
  574.         IF visual     THEN FreeVisualInfo(visual)
  575.         IF scr      THEN UnlockPubScreen(0,scr)
  576.  
  577. ENDPROC
  578.  
  579. store:LONG 0
  580.  
  581. PROC send()
  582.  
  583. DEF id,class2,msg:PTR TO intuimessage
  584.  
  585. IF (msg:=Gt_GetIMsg(win.userport))
  586.         class2:=msg.class
  587.         gad:=msg.iaddress
  588.         id:=gad.gadgetid
  589.         IF class2=IDCMP_GADGETDOWN OR IDCMP_GADGETUP
  590.                 IF id=1
  591.                     abort:=TRUE
  592.                 ENDIF
  593.         ENDIF
  594. Gt_ReplyIMsg(msg)
  595. ENDIF
  596.  
  597. UpSendCmd(dinfo,cinfo.decrunchadr,cinfo.offset,cinfo.decrunchlen,CMD_WRITE)
  598. SetAPen(stdrast,1)
  599. TextF(11,53,'Unpacking track \d',tracknr)
  600.  
  601. tracknr:=tracknr+1
  602. ENDPROC
  603.  
  604. scantrack:
  605. LEA store(PC),A0
  606. MOVE.L (A0),A4
  607. send()
  608. IF abort=FALSE
  609.     CLR.L D0
  610. ELSE
  611.     MOVE.L #999,D0
  612. ENDIF
  613. RTS
  614.  
  615. PROC checkdisk()
  616.  
  617. DEF ioport,ioreq:PTR TO iostd,dev
  618.  
  619. ioport:=CreateMsgPort()
  620. ioreq:=CreateIORequest(ioport,SIZEOF iostd)
  621. dev:=OpenDevice('trackdisk.device',unit,ioreq,0)
  622. IF dev=0
  623.     ioreq.command:=TD_PROTSTATUS
  624.     DoIO(ioreq)
  625.     IF (ioreq.error<>TDERR_DISKCHANGED)
  626.         IF (ioreq.actual=0)
  627.             RETURN 0
  628.         ELSE
  629.             RETURN 10
  630.         ENDIF
  631.     ELSE
  632.         RETURN 100
  633.     ENDIF
  634. ELSE
  635.     RETURN 1000
  636. ENDIF
  637. IF ioreq THEN CloseDevice(ioreq)
  638. IF ioport THEN DeleteMsgPort(ioport)
  639. IF ioreq THEN DeleteIORequest(ioreq)
  640. ENDPROC 0
  641.  
  642. PROC reqtoolsreq(tekst,but)
  643. ENDPROC RtEZRequestA(tekst,but,0,0,
  644.     [RT_UNDERSCORE,"_",
  645.     RT_REQPOS,REQPOS_CENTERSCR,
  646.     RT_WINDOW,mainwin,
  647.     RT_SCREEN,0,
  648.     RTEZ_FLAGS,EZREQF_CENTERTEXT,0])
  649.  
  650. PROC whyfail(num)
  651. SELECT num
  652.     CASE 999
  653.         StrCopy(string, 'User abort', ALL)
  654.     CASE ERR_OPEN
  655.         StrCopy(string,'Can''t Open File',ALL)
  656.     CASE ERR_READWRITE
  657.         StrCopy(string,'Read/Write Error',ALL)
  658.     CASE ERR_MEMORY
  659.         StrCopy(string,'Allocation Error (Out Of Memory)',ALL)
  660.     CASE ERR_DETERMINE
  661.         StrCopy(string,'Can''t Determine File',ALL)
  662.     CASE ERR_PASSWORD
  663.         StrCopy(string,'Illegal Password',ALL)
  664.     CASE ERR_HUNK
  665.         StrCopy(string,'Hunk Error',ALL)
  666.     CASE ERR_EXTERN
  667.         StrCopy(string,'Extern File Error',ALL)
  668.     CASE ERR_CORRUPT
  669.         StrCopy(string,'Crunched File Is Corrupted',ALL)
  670.     CASE ERR_DEVICE
  671.         StrCopy(string,'Illegal Device',ALL)
  672.     CASE ERR_DEVOPEN
  673.         StrCopy(string,'Couldn''t Open Device Or Create Port',ALL)
  674.     CASE ERR_CRC
  675.         StrCopy(string,'CRC Checksum Error',ALL)
  676.     CASE ERR_CHECKSUM
  677.         StrCopy(string,'Checksum Error',ALL)
  678.     CASE ERR_OLD
  679.         StrCopy(string,'Decruncher In Lib. Too Old',ALL)
  680.     CASE ERR_DEVERR
  681.         StrCopy(string,'Error From Device',ALL)
  682.     CASE ERR_PROTECT
  683.         StrCopy(string,'Couldn''t Set Protection Bits',ALL)
  684.     CASE ERR_OUTPUT
  685.         StrCopy(string,'Output File Error',ALL)
  686.     CASE ERR_OPENLIBRARY
  687.         StrCopy(string,'Couldn''t Open Library',ALL)
  688.     CASE ERR_UNKNOWN
  689.         StrCopy(string,'Unknown Error',ALL)
  690. ENDSELECT
  691. dodaj(list, string)
  692. ENDPROC
  693.  
  694. PROC setpath()
  695.  
  696. RtFileRequestA(reql,NIL,'Select path',[RTFI_FLAGS,FREQF_NOFILES,0])
  697. StrCopy(path2,reql.dir,ALL)
  698. pos:=(StrLen(path2)-1)+path2
  699. IF Char(pos)<>Char(':')
  700.         StrCopy(path,path2,ALL)
  701.         StrAdd(path,'/',1)
  702. ELSE
  703.         StrCopy(path,path2,ALL)
  704. ENDIF
  705.  
  706. ENDPROC reql.dir
  707.  
  708. PROC request(kind)
  709. DEF directory[255]:STRING, dir, out, req:PTR TO rtfilerequester
  710.     GetCurrentDirName(directory,256)
  711.     IF kind=LOAD THEN req:=reql ELSE req:=reqs
  712.     IF (out:=RtFileRequestA(req,file,'Select file',[RTFI_FLAGS,IF kind=LOAD THEN FREQF_MULTISELECT ELSE FREQF_SAVE,0]))
  713.             IF kind=LOAD
  714.                 flist:=out
  715.                 StrCopy(loaddir,req.dir,ALL)
  716.             ENDIF
  717.             dir:=req.dir
  718.             StrCopy(directory,dir,ALL)
  719.             AddPart(directory, file, 255)
  720.     ELSE
  721.         directory:=0
  722.     ENDIF
  723. StrCopy(name,directory,ALL)
  724. ENDPROC out
  725.